﻿<UserControl x:Class="ConsoleHoster.View.ConsoleView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:cv="clr-namespace:ConsoleHoster.View.Converters"
             xmlns:uc="clr-namespace:ConsoleHoster.View.Controls"
             xmlns:global="clr-namespace:ConsoleHoster.Model"
            xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="500" DataContextChanged="UserControl_DataContextChanged_1" SizeChanged="UserControl_SizeChanged_1">
    <UserControl.Resources>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <cv:ObjectToVisibilityConverter x:Key="cvConverter" />
        <cv:BoolToFontWeightConverter x:Key="cvBoolToFontWeightConverter" />

        <Style x:Key="BottomAlignedTextBoxBaseStyle"  
       TargetType="{x:Type TextBoxBase}" 
       BasedOn="{StaticResource {x:Type TextBoxBase}}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TextBoxBase}">
                        <Microsoft_Windows_Themes:ListBoxChrome x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderFocused="{TemplateBinding IsKeyboardFocusWithin}" SnapsToDevicePixels="true">
                            <ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                        </Microsoft_Windows_Themes:ListBoxChrome>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    </UserControl.Resources>
    <Grid Margin="2">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition MaxWidth="500" Width="{Binding Path=ExplorerViewWidth, Mode=TwoWay}" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid>
            <Grid.Background>
                <SolidColorBrush Color="{Binding Path=Project.BackgroundColor}" />
            </Grid.Background>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition MinHeight="32" Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <uc:ContentSearchPanel Panel.ZIndex="10" DataContext="{Binding Path=SearchVM}" HorizontalAlignment="Stretch" VerticalAlignment="Top" />

                <uc:MultiColorTextbox x:Name="mctHistory" VerticalContentAlignment="Bottom" IsReadOnly="True" Text="{Binding Path=Messages, Mode=OneWay}" VerticalScrollBarVisibility="Auto" d:LayoutOverrides="Margin" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FontWeight="{Binding Path=CurrentFontSettings.UseBoldFonts, Converter={StaticResource ResourceKey=cvBoolToFontWeightConverter}}" TextChanged="txbHistory_TextChanged" FontFamily="{Binding Path=CurrentFontSettings.FontFamily}" Style="{StaticResource BottomAlignedTextBoxBaseStyle}" Background="Transparent" IsReadOnlyCaretVisible="True" FontSize="{Binding Path=FontSize}" PreviewMouseWheel="mctHistory_PreviewMouseWheel" IsDocumentEnabled="True" Grid.Row="1">
                    <uc:MultiColorTextbox.Foreground>
                        <SolidColorBrush Color="{Binding Path=Project.MessageColor}" />
                    </uc:MultiColorTextbox.Foreground>
                </uc:MultiColorTextbox>
            </Grid>

            <GridSplitter Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Height="1" ResizeDirection="Rows" />

            <Border Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderThickness="0, 1, 0, 0">
                <Grid HorizontalAlignment="Stretch">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <TextBox x:Name="txtCommand" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" Text="{Binding CurrentCommand, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" d:LayoutOverrides="Margin" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalContentAlignment="Top" AcceptsReturn="True" AcceptsTab="False" BorderThickness="0, 0, 1, 1" IsEnabled="{Binding Path=IsAlive}" PreviewKeyDown="txtCommand_PreviewKeyDown" Background="Transparent" Cursor="IBeam" ForceCursor="True" TextChanged="txtCommand_TextChanged" FontSize="{Binding Path=FontSize}" ToolTip="Hit Ctrl+Enter for multiline commands" FontFamily="{Binding Path=CurrentFontSettings.FontFamily}" FontWeight="Bold" PreviewMouseWheel="txtCommand_PreviewMouseWheel">
                        <TextBox.Foreground>
                            <SolidColorBrush Color="{Binding Path=Project.MessageColor}" />
                        </TextBox.Foreground>
                        <TextBox.CaretBrush>
                            <SolidColorBrush Color="{Binding Path=Project.CaretColor}" />
                        </TextBox.CaretBrush>
                    </TextBox>
                    <Grid Grid.Column="2">
                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition />
                        </Grid.RowDefinitions>

                        <Button ToolTip="Previous command" Command="{Binding Path=RetrieveRecentCommand}" Cursor="Hand" Content="P">
                            <Button.CommandParameter>
                                <sys:Boolean>False</sys:Boolean>
                            </Button.CommandParameter>
                        </Button>
                        <Button Grid.Row="2" ToolTip="Next command" Command="{Binding Path=RetrieveRecentCommand}" Cursor="Hand" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Content="N">
                            <Button.CommandParameter>
                                <sys:Boolean>True</sys:Boolean>
                            </Button.CommandParameter>
                        </Button>
                    </Grid>
                </Grid>
            </Border>

            <TextBlock Text="{Binding Path=ErrorMessage}" Foreground="Red" Grid.Row="2" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Visibility="{Binding Path=ErrorMessage, Converter={StaticResource ResourceKey=cvConverter}}"/>
        </Grid>

        <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="1" Visibility="{Binding ShowExplorerPane, Converter={StaticResource BooleanToVisibilityConverter}}">
            <!-- Explorer pane-->
            <uc:DriveExplorerView HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Transparent" DataContext="{Binding Path=ExplorerVM}" />

        </Grid>

        <GridSplitter Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Left" Width="3" Background="#FFE8E8E8" Visibility="{Binding ShowExplorerPane, Converter={StaticResource BooleanToVisibilityConverter}}" />

        <Expander ExpandDirection="Left" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" IsExpanded="{Binding Path=ShowExplorerPane}" Grid.Column="2" VerticalAlignment="Center" Cursor="Hand" ToolTip="Ctrl-E" />
    </Grid>
</UserControl>
